package io.renren.softpark.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yunlong.common.utils.PageUtils;
import com.yunlong.common.utils.R;
import io.renren.softpark.dto.VerifySoftwareDto;
import io.renren.softpark.entity.SoftwareEntity;
import io.renren.softpark.form.SoftwareForm;
import io.renren.softpark.form.SoftwareUpdateForm;
import io.renren.softpark.service.SoftwareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mapping.callback.ReactiveEntityCallbacks;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 
 *
 * @author Cui
 * @email ${email}
 * @date 2020-08-14 09:24:18
 */
@RestController
@RequestMapping("generator/software")
public class SoftwareController {
    @Autowired
    private SoftwareService softwareService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = softwareService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/verify/list")
    public R verifyList(@RequestParam Map<String, Object> params){
        List<VerifySoftwareDto> data = softwareService.verifyColumn(params);
        data = softwareService.judgeVerify(data);
        return R.ok().put("data", data);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{softId}")
    public R info(@PathVariable("softId") String softId){
		SoftwareEntity software = softwareService.getById(softId);

        return R.ok().put("software", software);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SoftwareEntity software){
		softwareService.save(software);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SoftwareEntity software){
		softwareService.updateById(software);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] softIds){
		softwareService.removeByIds(Arrays.asList(softIds));

        return R.ok();
    }

    /**
     * 返回软件的详细信息
     */
    @RequestMapping("/detail")
    public R getDetailData(@RequestBody SoftwareForm softwareForm){

        return R.ok().put("detaiData",softwareService.getDetailData(softwareForm.getSoftId()));
    }

    @RequestMapping("/detailUpdate")
    public R updateDetailData(@RequestBody SoftwareUpdateForm softwareUpdateForm){
        softwareService.updateDetailData(softwareUpdateForm);
        return R.ok("信息更新成功");
    }
}
